/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sampleEntity;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author ASUS K43E
 */
@Entity
@Table(name = "BillDetail", catalog = "Lafitte", schema = "dbo")
@NamedQueries({
    @NamedQuery(name = "BillDetail.findAll", query = "SELECT b FROM BillDetail b"),
    @NamedQuery(name = "BillDetail.findByBillId", query = "SELECT b FROM BillDetail b WHERE b.billDetailPK.billId = :billId"),
    @NamedQuery(name = "BillDetail.findByProductId", query = "SELECT b FROM BillDetail b WHERE b.billDetailPK.productId = :productId"),
    @NamedQuery(name = "BillDetail.findByQuantity", query = "SELECT b FROM BillDetail b WHERE b.quantity = :quantity"),
    @NamedQuery(name = "BillDetail.findByUnitPrice", query = "SELECT b FROM BillDetail b WHERE b.unitPrice = :unitPrice"),
    @NamedQuery(name = "BillDetail.findByDiscount", query = "SELECT b FROM BillDetail b WHERE b.discount = :discount")})
public class BillDetail implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected BillDetailPK billDetailPK;
    @Basic(optional = false)
    @Column(name = "quantity", nullable = false)
    private int quantity;
    @Basic(optional = false)
    @Column(name = "unitPrice", nullable = false)
    private double unitPrice;
    @Column(name = "discount", precision = 15)
    private Double discount;
    @JoinColumn(name = "productId", referencedColumnName = "productId", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Product product;
    @JoinColumn(name = "billId", referencedColumnName = "billId", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Bill bill;

    public BillDetail() {
    }

    public BillDetail(BillDetailPK billDetailPK) {
        this.billDetailPK = billDetailPK;
    }

    public BillDetail(BillDetailPK billDetailPK, int quantity, double unitPrice) {
        this.billDetailPK = billDetailPK;
        this.quantity = quantity;
        this.unitPrice = unitPrice;
    }

    public BillDetail(int billId, String productId) {
        this.billDetailPK = new BillDetailPK(billId, productId);
    }

    public BillDetailPK getBillDetailPK() {
        return billDetailPK;
    }

    public void setBillDetailPK(BillDetailPK billDetailPK) {
        this.billDetailPK = billDetailPK;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public double getUnitPrice() {
        return unitPrice;
    }

    public void setUnitPrice(double unitPrice) {
        this.unitPrice = unitPrice;
    }

    public Double getDiscount() {
        return discount;
    }

    public void setDiscount(Double discount) {
        this.discount = discount;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public Bill getBill() {
        return bill;
    }

    public void setBill(Bill bill) {
        this.bill = bill;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (billDetailPK != null ? billDetailPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof BillDetail)) {
            return false;
        }
        BillDetail other = (BillDetail) object;
        if ((this.billDetailPK == null && other.billDetailPK != null) || (this.billDetailPK != null && !this.billDetailPK.equals(other.billDetailPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "sampleEntity.BillDetail[billDetailPK=" + billDetailPK + "]";
    }

}
